/**
 * Created by pan on 2017/6/22.
 */

var express = require('express');
var router = express.Router();
var superagent = require('superagent');

router.get('/', function(req, res, next) {
    superagent
        .get(
            `https://b.zhuishushenqi.com/category/rankinfo?ajax=ajax&size=100&st=1&node=${
                req.query.node
            }&token=&type=&packageName=`
        )
        .end(function(err, response) {
            if (err) {
                res.send({
                    result: 0,
                    msg: err,
                });
            } else {
                const { text } = response;
                try {
                    const { book } = JSON.parse(text);
                    res.send({
                        result: 1,
                        data: book,
                    });
                } catch (e) {
                    res.send({
                        result: 0,
                        msg: e.toString(),
                    });
                }
            }
        });
});

module.exports = router;
